﻿using System;
using System.Web.Caching;

namespace Mystery.SharePoint
{
    /// <summary>
    /// Extension methods for HashTable
    /// </summary>
    public static class CacheExtension
    {
        /// <summary>
        /// Reads a value from the cache
        /// </summary>
        /// <param name="ht"></param>
        /// <param name="key">The key of the value we are looking for</param>
        /// <param name="defaultValue">A value to use if the key doesn't exist in the cache</param>
        /// <returns>The value stored in the cache or the default value</returns>
        public static T Read<T>(this Cache cache, string key, T defaultValue)
        {
            if (cache == null) throw new ArgumentNullException("cache");

            object obj = cache[key];
            if (obj == null)
            {
                return defaultValue;
            }
            return (T)obj;
        }
    }
}
